package com.lighting.shortlink.project.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * MyBatis-Plus 原数据自动填充类
 * @author : lighting
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
//    strictInsertFill：插入操作时调用
    public void insertFill(MetaObject metaObject) {
//      时间默认为当前系统时间
        strictInsertFill(metaObject,"createTime",Date::new, Date.class);
        strictInsertFill(metaObject,"updateTime",Date::new, Date.class);
//        删除标识默认为 0
        strictInsertFill(metaObject,"delFlag",()->0, Integer.class);
    }

    @Override
//    updateFill：更新操作时调用
    public void updateFill(MetaObject metaObject) {
//        strictInsertFill(metaObject,"updateTime",()->new Date(),Date.class); //正常 lambda
        strictInsertFill(metaObject,"updateTime",Date::new,Date.class);
    }
}
